home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / BlitzList / BlitzListFiles / BlitzC2P.lha / programming / blitz2 / programs / c2pCACHE.ascii < prev    next >
Encoding:
Text File  |  1998-07-27  |  10.4 KB  |  488 lines

  1. WBStartup
  2. NoCli
  3.  
  4. ; Results on 040/25Mhz CPU:
  5. ; PAL       50Hz 320x200 256-colours runs @50fps
  6. ; DoublePAL 48Hz 320x200 256-colours runs @47.1fps
  7. ; PAL       50Hz 320x256 256-colours runs @38.3fps
  8. ; DoublePAL 48Hz 320x256 256-colours runs @35.3fps
  9.  
  10. ; Results on 060/50:
  11. ; PAL @49.6fps 320x256
  12. ; PAL @66.1fps 320x200
  13.  
  14. ;Width must be multiple of 32!
  15. #scrwidth=320 ; This is the width of chunky bitmap and also of the planar bitmap
  16. #scrheight=256 ; This is the height of the chunky bitmap and also of the planar bitmap
  17.  
  18. #screensize=#scrwidth*#scrheight ; constants needed by the c2p
  19. #screensize4=#screensize/4
  20. #plane=#screensize/8
  21.  
  22. Statement c2p{A.l,B.l}
  23. .c2p
  24.  
  25.   MOVE.l  d0,a0
  26.   MOVE.l  d1,a1
  27.  
  28. ;Original sourcecode text:
  29. ;
  30. ;---------------------------------------------------------------------------
  31. ;5 pass cpu only c2p for 040/060 -
  32. ;
  33. ;~13820us for 320x256 (216 rasterlines)
  34. ;with no dma activated.
  35. ;(usual copyspeed is ~13960 us)
  36. ;
  37. ;(W) Mai 1998 by Tim Bvscke aka. Azure
  38. ;azure@gmx.net
  39. ;
  40. ;This Chunky to Planar converter is converting/writing faster than
  41. ;a usual longword loop is copying from fastmem to chipmem. (Copyspeed)
  42. ;
  43. ;This is possible due to some caching-tricks.
  44. ;
  45. ;---------------------------------------------------------------------------
  46. ;IN:
  47. ; a0   =source
  48. ; a1   =target
  49. ;----------------------------------------------------------------------------
  50.  
  51.  
  52.  
  53. ;MERGE    d1,d2,tmp,mask,shift
  54. Macro MERGE
  55.   MOVE.l   `2,`3
  56.   LSR.l   #`5,`3
  57.     EOR.l    `1,`3
  58.     AND.l    `4,`3
  59.     EOR.l    `3,`1
  60.     LSL.l   #`5,`3
  61.     EOR.l    `3,`2
  62. End Macro
  63.  
  64. Macro MERGE1
  65.   MOVE.l   `2,`3
  66.   LSR.l    #1,`3
  67.     EOR.l    `1,`3
  68.     AND.l    `4,`3
  69.     EOR.l    `3,`1
  70.     ADD.l    `3,`3
  71.     EOR.l    `3,`2
  72. End Macro
  73.  
  74. Macro MERGEw
  75.     SWAP  `2
  76.     EOR.w `1,`2
  77.     EOR.w `2,`1
  78.     EOR.w `1,`2
  79.     SWAP  `2
  80. End Macro
  81.  
  82. _chunky2planar
  83.  
  84.     MOVEM.l a3-a6,-(a7)
  85.     MOVE.l  #screensize,d0
  86.  
  87.     LEA 0(a0,d0.l),a2
  88.     MOVE.l  a2,smc+2
  89.  
  90.     MOVEM.l a0/a1/a6,-(a7)
  91.     MOVE.l  $4,a6
  92.     JSR -636(a6)  ;flush caches
  93.     MOVEM.l (a7)+,a0/a1/a6
  94.  
  95.     MOVE.l  (a0),d0
  96.     MOVE.l  2*4+0(a0),d2
  97.     MOVE.l  4*4+0(a0),d4
  98.     MOVE.l  6*4+0(a0),d6
  99.  
  100.     !MERGEw{d0,d4}
  101.     !MERGEw{d2,d6}
  102.  
  103.     !MERGE{d0,d2,d3,#$00FF00FF,8}
  104.     !MERGE{d4,d6,d3,#$00FF00FF,8}
  105.  
  106.     MOVE.l  1*4(a0),d1
  107.     MOVE.l  3*4(a0),d3
  108.     MOVE.l  5*4(a0),d5
  109.     MOVE.l  7*4(a0),d7
  110.  
  111.     ADDA.w  #32,a0
  112.     MOVE.l  d4,a6   ;  d3->a6
  113.  
  114.     !MERGEw{d1,d5}
  115.     ADD.l #screensize4*1,a1
  116.     !MERGEw{d3,d7}
  117.     !MERGE{d5,d7,d4,#$00FF00FF,8}
  118.     !MERGE{d1,d3,d4,#$00FF00FF,8}
  119.     !MERGE{d0,d1,d4,#$0F0F0F0F,4}
  120.     !MERGE{d2,d3,d4,#$0F0F0F0F,4}
  121.     !MERGE{d6,d7,d4,#$0F0F0F0F,4}
  122.     EXG.l d1,a6   ;d4-> a6
  123.     !MERGE{d1,d5,d4,#$0F0F0F0F,4}
  124.     ADD.l #screensize4*1,a1
  125.     !MERGE{d0,d1,d4,#$33333333,2}
  126.     !MERGE{d2,d6,d4,#$33333333,2}
  127.     ADD.l #screensize4*1+4,a1
  128.     !MERGE{d3,d7,d4,#$33333333,2}
  129.     EXG.l d1,a6   ;d4=a6
  130.     !MERGE1{d0,d2,d4,#$55555555}
  131.     MOVE.l  d0,plane(a1) ;->Plane 7
  132.     EXG.l d0,a6
  133.     !MERGE{d1,d5,d4,#$33333333,2}
  134.     !MERGE1{d0,d6,d4,#$55555555}
  135.     MOVE.l  d0,a5
  136.     !MERGE1{d1,d3,d4,#$55555555}
  137.     MOVE.l  d2,(a1)
  138.     MOVE.l  d6,a4
  139.     MOVE.l  d1,a3
  140.     SUB.l #screensize4*3,a1
  141.     !MERGE1{d5,d7,d4,#$55555555}
  142.     MOVE.l  d7,a6
  143.     MOVE.l  d3,a2
  144. loop
  145.     TST.w 0*16+6(a0)
  146.     TST.w 1*16+6(a0)
  147.     TST.w 2*16+6(a0)
  148.     TST.w 3*16+6(a0)
  149.  
  150.     TST.w 4*16+6(a0)
  151.     TST.w 5*16+6(a0)
  152.     TST.w 6*16+6(a0)
  153.     TST.w 7*16+6(a0)  ;this is the tricky part
  154.  
  155.     MOVE.l  (a0),d0
  156.     MOVE.l  2*4+0(a0),d2
  157.     MOVE.l  4*4+0(a0),d4
  158.     MOVE.l  6*4+0(a0),d6
  159.  
  160.     MOVE.l  d5,plane(a1) ;  Plane 1
  161.  
  162.     !MERGEw{d0,d4}
  163.     !MERGEw{d2,d6}
  164.  
  165.     !MERGE{d0,d2,d3,#$00FF00FF,8}
  166.     !MERGE{d4,d6,d3,#$00FF00FF,8}
  167.  
  168.     MOVE.l  1*4(a0),d1
  169.     MOVE.l  3*4(a0),d3
  170.     MOVE.l  5*4(a0),d5
  171.     MOVE.l  7*4(a0),d7
  172.  
  173.     ADDA.l  #32,a0
  174.     MOVE.l  a6,(a1)   ;  Plane 0
  175.     MOVE.l  d4,a6   ;  d3->a6
  176.  
  177.     !MERGEw{d1,d5}
  178.     ADD.l #screensize4*1,a1
  179.     !MERGEw{d3,d7}
  180.  
  181.     MOVE.l  a3,plane(a1) ; 3
  182.  
  183.     !MERGE{d5,d7,d4,#$00FF00FF,8}
  184.     !MERGE{d1,d3,d4,#$00FF00FF,8}
  185.     !MERGE{d0,d1,d4,#$0F0F0F0F,4}
  186.     !MERGE{d2,d3,d4,#$0F0F0F0F,4}
  187.     MOVE.l  a2,(a1)   ; 2
  188.     !MERGE{d6,d7,d4,#$0F0F0F0F,4}
  189.     EXG.l d1,a6   ;d4-> a6
  190.     !MERGE{d1,d5,d4,#$0F0F0F0F,4}
  191.     ADD.l #screensize4*1,a1
  192.     MOVE.l  a5,plane(a1) ; 5
  193.  
  194.     !MERGE{d0,d1,d4,#$33333333,2}
  195.     !MERGE{d2,d6,d4,#$33333333,2}
  196.     MOVE.l  a4,(a1)   ; 4
  197.     ADD.l #screensize4*1+4,a1
  198.     !MERGE{d3,d7,d4,#$33333333,2}
  199.     EXG.l d1,a6   ;d4=a6
  200.  
  201.     !MERGE1{d0,d2,d4,#$55555555}
  202.  
  203.     MOVE.l  d0,plane(a1) ;->Plane 7
  204.  
  205.     EXG.l d0,a6
  206.  
  207.     !MERGE{d1,d5,d4,#$33333333,2}
  208.     !MERGE1{d0,d6,d4,#$55555555}
  209.     MOVE.l  d0,a5
  210.     !MERGE1{d1,d3,d4,#$55555555}
  211.     MOVE.l  d2,(a1)
  212.     MOVE.l  d6,a4
  213.     MOVE.l  d1,a3
  214.     SUB.l #screensize4*3,a1
  215.     !MERGE1{d5,d7,d4,#$55555555}
  216.     MOVE.l  d7,a6
  217.     MOVE.l  d3,a2
  218.  
  219.  
  220.     MOVE.l  (a0),d0
  221.     MOVE.l  2*4+0(a0),d2
  222.     MOVE.l  4*4+0(a0),d4
  223.     MOVE.l  6*4+0(a0),d6
  224.  
  225.     MOVE.l  d5,plane(a1) ;  Plane 1
  226.  
  227.     !MERGEw{d0,d4}
  228.     !MERGEw{d2,d6}
  229.  
  230.     !MERGE{d0,d2,d3,#$00FF00FF,8}
  231.     !MERGE{d4,d6,d3,#$00FF00FF,8}
  232.  
  233.     MOVE.l  1*4(a0),d1
  234.     MOVE.l  3*4(a0),d3
  235.     MOVE.l  5*4(a0),d5
  236.     MOVE.l  7*4(a0),d7
  237.  
  238.     ADDA.l  #32,a0
  239.     MOVE.l  a6,(a1)   ;  Plane 0
  240.     MOVE.l  d4,a6   ;  d3->a6
  241.  
  242.     !MERGEw{d1,d5}
  243.     ADD.l #screensize4*1,a1
  244.     !MERGEw{d3,d7}
  245.  
  246.     MOVE.l  a3,plane(a1) ; 3
  247.  
  248.     !MERGE{d5,d7,d4,#$00FF00FF,8}
  249.     !MERGE{d1,d3,d4,#$00FF00FF,8}
  250.     !MERGE{d0,d1,d4,#$0F0F0F0F,4}
  251.     !MERGE{d2,d3,d4,#$0F0F0F0F,4}
  252.     MOVE.l  a2,(a1)   ; 2
  253.     !MERGE{d6,d7,d4,#$0F0F0F0F,4}
  254.     EXG.l d1,a6   ;d4-> a6
  255.     !MERGE{d1,d5,d4,#$0F0F0F0F,4}
  256.     ADD.l #screensize4*1,a1
  257.     MOVE.l  a5,plane(a1) ; 5
  258.  
  259.     !MERGE{d0,d1,d4,#$33333333,2}
  260.     !MERGE{d2,d6,d4,#$33333333,2}
  261.     MOVE.l  a4,(a1)   ; 4
  262.     ADD.l #screensize4*1+4,a1
  263.     !MERGE{d3,d7,d4,#$33333333,2}
  264.     EXG.l d1,a6   ;d4=a6
  265.  
  266.     !MERGE1{d0,d2,d4,#$55555555}
  267.  
  268.     MOVE.l  d0,plane(a1) ;->Plane 7
  269.  
  270.     EXG.l d0,a6
  271.  
  272.     !MERGE{d1,d5,d4,#$33333333,2}
  273.     !MERGE1{d0,d6,d4,#$55555555}
  274.     MOVE.l  d0,a5
  275.     !MERGE1{d1,d3,d4,#$55555555}
  276.     MOVE.l  d2,(a1)
  277.     MOVE.l  d6,a4
  278.     MOVE.l  d1,a3
  279.     SUB.l #screensize4*3,a1
  280.     !MERGE1{d5,d7,d4,#$55555555}
  281.     MOVE.l  d7,a6
  282.     MOVE.l  d3,a2
  283.  
  284.  
  285.     MOVE.l  (a0),d0
  286.     MOVE.l  2*4+0(a0),d2
  287.     MOVE.l  4*4+0(a0),d4
  288.     MOVE.l  6*4+0(a0),d6
  289.  
  290.     MOVE.l  d5,plane(a1) ;  Plane 1
  291.  
  292.     !MERGEw{d0,d4}
  293.     !MERGEw{d2,d6}
  294.  
  295.     !MERGE{d0,d2,d3,#$00FF00FF,8}
  296.     !MERGE{d4,d6,d3,#$00FF00FF,8}
  297.  
  298.     MOVE.l  1*4(a0),d1
  299.     MOVE.l  3*4(a0),d3
  300.     MOVE.l  5*4(a0),d5
  301.     MOVE.l  7*4(a0),d7
  302.  
  303.     ADDA.l  #32,a0
  304.     MOVE.l  a6,(a1)   ;  Plane 0
  305.     MOVE.l  d4,a6   ;  d3->a6
  306.  
  307.     !MERGEw{d1,d5}
  308.     ADD.l #screensize4*1,a1
  309.     !MERGEw{d3,d7}
  310.  
  311.     MOVE.l  a3,plane(a1) ; 3
  312.  
  313.     !MERGE{d5,d7,d4,#$00FF00FF,8}
  314.     !MERGE{d1,d3,d4,#$00FF00FF,8}
  315.     !MERGE{d0,d1,d4,#$0F0F0F0F,4}
  316.     !MERGE{d2,d3,d4,#$0F0F0F0F,4}
  317.     MOVE.l  a2,(a1)   ; 2
  318.     !MERGE{d6,d7,d4,#$0F0F0F0F,4}
  319.     EXG.l d1,a6   ;d4-> a6
  320.     !MERGE{d1,d5,d4,#$0F0F0F0F,4}
  321.     ADD.l #screensize4*1,a1
  322.     MOVE.l  a5,plane(a1) ; 5
  323.  
  324.     !MERGE{d0,d1,d4,#$33333333,2}
  325.     !MERGE{d2,d6,d4,#$33333333,2}
  326.     MOVE.l  a4,(a1)   ; 4
  327.     ADD.l #screensize4*1+4,a1
  328.     !MERGE{d3,d7,d4,#$33333333,2}
  329.     EXG.l d1,a6   ;d4=a6
  330.  
  331.     !MERGE1{d0,d2,d4,#$55555555}
  332.  
  333.     MOVE.l  d0,plane(a1) ;->Plane 7
  334.  
  335.     EXG.l d0,a6
  336.  
  337.     !MERGE{d1,d5,d4,#$33333333,2}
  338.     !MERGE1{d0,d6,d4,#$55555555}
  339.     MOVE.l  d0,a5
  340.     !MERGE1{d1,d3,d4,#$55555555}
  341.     MOVE.l  d2,(a1)
  342.     MOVE.l  d6,a4
  343.     MOVE.l  d1,a3
  344.     SUB.l #screensize4*3,a1
  345.     !MERGE1{d5,d7,d4,#$55555555}
  346.     MOVE.l  d7,a6
  347.     MOVE.l  d3,a2
  348.  
  349. smc
  350.     CMP.l #$0BADC0DE,a0
  351.     BGE   quit
  352.  
  353.     MOVE.l  (a0),d0
  354.     MOVE.l  2*4+0(a0),d2
  355.     MOVE.l  4*4+0(a0),d4
  356.     MOVE.l  6*4+0(a0),d6
  357.  
  358.     MOVE.l  d5,plane(a1) ;  Plane 1
  359.  
  360.     !MERGEw{d0,d4}
  361.     !MERGEw{d2,d6}
  362.  
  363.     !MERGE{d0,d2,d3,#$00FF00FF,8}
  364.     !MERGE{d4,d6,d3,#$00FF00FF,8}
  365.  
  366.     MOVE.l  1*4(a0),d1
  367.     MOVE.l  3*4(a0),d3
  368.     MOVE.l  5*4(a0),d5
  369.     MOVE.l  7*4(a0),d7
  370.  
  371.     ADDA.w  #32,a0
  372.     MOVE.l  a6,(a1)   ;  Plane 0
  373.     MOVE.l  d4,a6   ;  d3->a6
  374.  
  375.     !MERGEw{d1,d5}
  376.     ADD.l #screensize4*1,a1
  377.  
  378.     !MERGEw{d3,d7}
  379.  
  380.     MOVE.l  a3,plane(a1) ; 3
  381.     !MERGE{d5,d7,d4,#$00FF00FF,8}
  382.     !MERGE{d1,d3,d4,#$00FF00FF,8}
  383.     !MERGE{d0,d1,d4,#$0F0F0F0F,4}
  384.     MOVE.l  a2,(a1)   ; 2
  385.     !MERGE{d2,d3,d4,#$0F0F0F0F,4}
  386.     !MERGE{d6,d7,d4,#$0F0F0F0F,4}
  387.     EXG.l d1,a6   ;d4-> a6
  388.     !MERGE{d1,d5,d4,#$0F0F0F0F,4}
  389.     ADD.l #screensize4*1,a1
  390.  
  391.     MOVE.l  a5,plane(a1) ; 5
  392.  
  393.     !MERGE{d0,d1,d4,#$33333333,2}
  394.     !MERGE{d2,d6,d4,#$33333333,2}
  395.     MOVE.l  a4,(a1)   ; 4
  396.     ADD.l #screensize4*1+4,a1
  397.     !MERGE{d3,d7,d4,#$33333333,2}
  398.     EXG.l d1,a6   ;d4=a6
  399.     !MERGE1{d0,d2,d4,#$55555555}
  400.  
  401.     MOVE.l  d0,plane(a1) ;->Plane 7
  402.  
  403.     EXG.l d0,a6
  404.     !MERGE{d1,d5,d4,#$33333333,2}
  405.     !MERGE1{d0,d6,d4,#$55555555}
  406.     MOVE.l  d0,a5
  407.     !MERGE1{d1,d3,d4,#$55555555}
  408.     MOVE.l  d2,(a1)
  409.     MOVE.l  d6,a4
  410.     MOVE.l  d1,a3
  411.     SUB.l #screensize4*3,a1
  412.     !MERGE1{d5,d7,d4,#$55555555}
  413.     MOVE.l  d7,a6
  414.     MOVE.l  d3,a2
  415.  
  416.     JMP loop
  417. quit
  418.     MOVE.l  d5,plane(a1)
  419.     MOVE.l  a6,(a1)
  420.     ADD.l #screensize4*1,a1
  421.     MOVE.l  a3,plane(a1)
  422.     MOVE.l  a2,(a1)
  423.     ADD.l #screensize4*1,a1
  424.     MOVE.l  a5,plane(a1)
  425.     MOVE.l  a4,(a1)
  426.  
  427.     MOVEM.l (a7)+,a3-a6
  428.  
  429.   AsmExit
  430. End Statement
  431.  
  432.  
  433. ; The following program is just a demonstration of how to get the c2p working.
  434. ; You must cludge bitmaps to 8 bytes past the start of the planar buffer,
  435. ; but tell the c2p routine to output to 4 bytes past the start of the planar buffer.
  436. ; This is because it outputs a longword of temporary data to the planar buffer
  437. ; before commencing the conversion, and keeps the bitmap data 64-bit aligned
  438. ; so that if you are working with o/s screens they will use 64-bit datafetch.
  439. .blitzprogram
  440. ; Setup
  441. InitBank 0,(#scrwidth*#scrheight)+1000,2|65536 ; Chipram planar buffer
  442. CludgeBitMap 0,#scrwidth,#scrheight,8,Bank(0)+8
  443. InitPalette 0,256
  444. For c=0 To 255
  445.   AGAPalRGB 0,c,Rnd(c),Rnd(c),Rnd(c)
  446. Next c
  447. AGAPalRGB 0,0,0,0,0
  448. Screen 0,0,0,#scrwidth,#scrheight,8,0,"c2p test",0,0,0
  449. Use Palette 0
  450. VWait 50
  451. baseaddress1.l=AllocMem(#scrwidth*#scrheight,$10000) ; Fastram chunky buffer
  452.  
  453. ; Put something into the chunky buffer so we can see it working
  454. GetReg a0,baseaddress1
  455. MOVE.l  #0,d0
  456. MOVE.l  #screensize-1,d1
  457. cloop
  458.   MOVE.b  d0,(a0)+
  459.   ADDQ.l  #1,d0
  460.   SUBQ.l  #1,d1
  461.   TST.l   d1
  462.   BLT     done
  463.   BRA     cloop
  464. done
  465.  
  466. ; Do the c2p test
  467. VWait 20
  468. Forbid_
  469. VWait
  470. ResetTimer
  471. For time=1 To 800
  472.   c2p{baseaddress1,Bank(0)+4} ; Convert chunky to planar
  473. Next time
  474. t=Ticks
  475. VWait 2 : Permit_
  476. VWait 20
  477. FindScreen 0
  478. Window 0,0,11,640,100,0,"Test results for c2p",0,0
  479. WindowOutput 0
  480. NPrint "Routine performed @ ",50/(t/800),"fps - ",t," ticks"
  481. NPrint " "
  482. NPrint "Press mousebutton..."
  483. Free Screen 0
  484. MouseWait
  485. Free Window 0
  486. End
  487.  
  488.